package com.lyz.dataStructure.JianZhiOffer;/**
 * @Author:759057893@qq.com Lyz
 * @Date: ${Date} 21:20
 * @Description:
 **/

import java.util.LinkedList;
import java.util.List;

/**
 *@Author:759057893@qq.com Lyz
 *@Date: 2019/6/22 21:20
 *@Description:
 **/


public class Test18 {
    public static ListNode FindKthToTail(ListNode head,int k) {
        if(head ==null){
            return null;
        }
        ListNode p1 = head;
        while(p1!=null&& k-- >0)
            p1 = p1.next;
        if(k>0)
            return null ;
        ListNode p2 =head;
        while(p1!=null){
            p1 =p1.next;
            p2 = p2.next;
        }
        return p2;
    }

    public static void main(String[] args) {
        ListNode head = new ListNode(1);
        ListNode node1  = new ListNode(2);
        ListNode node2  = new ListNode(3);
        ListNode node3  = new ListNode(4);
        ListNode node4  = new ListNode(5);
        ListNode node5  = new ListNode(6);
        ListNode node6  = new ListNode(7);
        head.val=10;
        node1.val=10;
        node2.val=10;
        node3.val=10;
        node4.val=10;
        node5.val=10;
        node6.val=10;
        head.next = node1;
        node1.next = node2;
        node2.next =node3;
        node3.next=node4;
        node4.next=node5;
        node5.next=node6;

        System.out.println(FindKthToTail(node6,3));
    }

}


